#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/6/23 11:39
# @Author  : Chenmm
# @File    : course_schema.py
# @Software: PyCharm

from pydantic import BaseModel, Field
from typing import Optional, List

from common.constant import SaleEnum


class Courses(BaseModel):
    """创建课程"""
    name: str = Field(min_length=2, max_length=50)
    icon: Optional[str] = None
    desc: Optional[str] = None
    catalog: Optional[str] = None
    onsale: Optional[SaleEnum] = None
    owner: Optional[int] = None
    like_num: Optional[int] = 0


class CourseCommentBase(BaseModel):
    user: str
    pid: Optional[int] = None
    add_time: str
    context: str


class CourseCommentOut(CourseCommentBase):
    id: int
    top: int


class CourseDetail(Courses):
    id: int
    owner: str  # 此处重写该字段，返回给客户端时展示用户名而非id
    comment: List[CourseCommentOut] = []


class CourseEdit(Courses):
    id: int


class CourseCommentModel(BaseModel):
    """发起评论参数"""
    id: int  # 课程id
    comment: str = Field(min_length=1)
    pid: Optional[int] = None